package o;

import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import java.util.Map;
import java.util.concurrent.Executor;

public class to implements tm, o.ut.a, c {
    private static final boolean ˏ = Log.isLoggable("Engine", 2);
    private final tv ʻ;
    private final d ʼ;
    private final td ʽ;
    private final tt ˊ;
    private final ut ˋ;
    private final tl ˎ;
    private final e ॱ;
    private final a ॱॱ;

    @VisibleForTesting
    static class a {
        final o.hg.e<th<?>> ˊ = aat.ॱ(150, new o.aat.a<th<?>>(this) {
            final /* synthetic */ a ˏ;

            {
                this.ˏ = r1;
            }

            public /* synthetic */ Object ॱ() {
                return ˏ();
            }

            public th<?> ˏ() {
                return new th(this.ˏ.ˋ, this.ˏ.ˊ);
            }
        });
        final d ˋ;
        private int ˎ;

        a(d dVar) {
            this.ˋ = dVar;
        }

        <R> th<R> ˏ(rh rhVar, Object obj, tn tnVar, sa saVar, int i, int i2, Class<?> cls, Class<R> cls2, rl rlVar, tf tfVar, Map<Class<?>, si<?>> map, boolean z, boolean z2, boolean z3, sc scVar, b<R> bVar) {
            th thVar = (th) aas.ˎ((th) this.ˊ.ˎ());
            int i3 = this.ˎ;
            this.ˎ = i3 + 1;
            return thVar.ˊ(rhVar, obj, tnVar, saVar, i, i2, cls, cls2, rlVar, tfVar, map, z, z2, z3, scVar, bVar, i3);
        }
    }

    public class b {
        final /* synthetic */ to ˋ;
        private final zq ˎ;
        private final tk<?> ˏ;

        b(to toVar, zq zqVar, tk<?> tkVar) {
            this.ˋ = toVar;
            this.ˎ = zqVar;
            this.ˏ = tkVar;
        }

        public void ˊ() {
            synchronized (this.ˋ) {
                this.ˏ.ˏ(this.ˎ);
            }
        }
    }

    static class d implements d {
        private volatile uj ˎ;
        private final o.uj.b ॱ;

        d(o.uj.b bVar) {
            this.ॱ = bVar;
        }

        public uj ˊ() {
            if (this.ˎ == null) {
                synchronized (this) {
                    if (this.ˎ == null) {
                        this.ˎ = this.ॱ.ॱ();
                    }
                    if (this.ˎ == null) {
                        this.ˎ = new us();
                    }
                }
            }
            return this.ˎ;
        }
    }

    @VisibleForTesting
    static class e {
        final o.hg.e<tk<?>> ʽ = aat.ॱ(150, new o.aat.a<tk<?>>(this) {
            final /* synthetic */ e ˏ;

            {
                this.ˏ = r1;
            }

            public /* synthetic */ Object ॱ() {
                return ˊ();
            }

            public tk<?> ˊ() {
                return new tk(this.ˏ.ˏ, this.ˏ.ॱ, this.ˏ.ˎ, this.ˏ.ˊ, this.ˏ.ˋ, this.ˏ.ᐝ, this.ˏ.ʽ);
            }
        });
        final uv ˊ;
        final tm ˋ;
        final uv ˎ;
        final uv ˏ;
        final uv ॱ;
        final c ᐝ;

        e(uv uvVar, uv uvVar2, uv uvVar3, uv uvVar4, tm tmVar, c cVar) {
            this.ˏ = uvVar;
            this.ॱ = uvVar2;
            this.ˎ = uvVar3;
            this.ˊ = uvVar4;
            this.ˋ = tmVar;
            this.ᐝ = cVar;
        }

        <R> tk<R> ˏ(sa saVar, boolean z, boolean z2, boolean z3, boolean z4) {
            return ((tk) aas.ˎ((tk) this.ʽ.ˎ())).ˎ(saVar, z, z2, z3, z4);
        }
    }

    public to(ut utVar, o.uj.b bVar, uv uvVar, uv uvVar2, uv uvVar3, uv uvVar4, boolean z) {
        this(utVar, bVar, uvVar, uvVar2, uvVar3, uvVar4, null, null, null, null, null, null, z);
    }

    @VisibleForTesting
    to(ut utVar, o.uj.b bVar, uv uvVar, uv uvVar2, uv uvVar3, uv uvVar4, tt ttVar, tl tlVar, td tdVar, e eVar, a aVar, tv tvVar, boolean z) {
        e eVar2;
        this.ˋ = utVar;
        this.ʼ = new d(bVar);
        if (tdVar == null) {
            td tdVar2 = new td(z);
        }
        this.ʽ = tdVar;
        tdVar.ˋ(this);
        if (tlVar == null) {
            tlVar = new tl();
        }
        this.ˎ = tlVar;
        if (ttVar == null) {
            ttVar = new tt();
        }
        this.ˊ = ttVar;
        if (eVar == null) {
            eVar2 = new e(uvVar, uvVar2, uvVar3, uvVar4, this, this);
        } else {
            eVar2 = eVar;
        }
        this.ॱ = eVar2;
        if (aVar == null) {
            a aVar2 = new a(this.ʼ);
        }
        this.ॱॱ = aVar;
        if (tvVar == null) {
            tvVar = new tv();
        }
        this.ʻ = tvVar;
        utVar.ˏ(this);
    }

    public <R> b ˏ(rh rhVar, Object obj, sa saVar, int i, int i2, Class<?> cls, Class<R> cls2, rl rlVar, tf tfVar, Map<Class<?>, si<?>> map, boolean z, boolean z2, sc scVar, boolean z3, boolean z4, boolean z5, boolean z6, zq zqVar, Executor executor) {
        long ॱ = ˏ ? aaq.ॱ() : 0;
        tn ˎ = this.ˎ.ˎ(obj, saVar, i, i2, map, cls, cls2, scVar);
        synchronized (this) {
            tx ˏ = ˏ(ˎ, z3, ॱ);
            if (ˏ == null) {
                b ˎ2 = ˎ(rhVar, obj, saVar, i, i2, cls, cls2, rlVar, tfVar, map, z, z2, scVar, z3, z4, z5, z6, zqVar, executor, ˎ, ॱ);
                return ˎ2;
            }
            zqVar.ˋ(ˏ, rz.MEMORY_CACHE);
            return null;
        }
    }

    private <R> b ˎ(rh rhVar, Object obj, sa saVar, int i, int i2, Class<?> cls, Class<R> cls2, rl rlVar, tf tfVar, Map<Class<?>, si<?>> map, boolean z, boolean z2, sc scVar, boolean z3, boolean z4, boolean z5, boolean z6, zq zqVar, Executor executor, tn tnVar, long j) {
        tk ˋ = this.ˊ.ˋ((sa) tnVar, z6);
        if (ˋ != null) {
            ˋ.ˏ(zqVar, executor);
            if (ˏ) {
                ॱ("Added to existing load", j, tnVar);
            }
            return new b(this, zqVar, ˋ);
        }
        b ˏ = this.ॱ.ˏ(tnVar, z3, z4, z5, z6);
        th ˏ2 = this.ॱॱ.ˏ(rhVar, obj, tnVar, saVar, i, i2, cls, cls2, rlVar, tfVar, map, z, z2, z6, scVar, ˏ);
        this.ˊ.ˏ(tnVar, ˏ);
        ˏ.ˏ(zqVar, executor);
        ˏ.ˋ(ˏ2);
        if (ˏ) {
            ॱ("Started new load", j, tnVar);
        }
        return new b(this, zqVar, ˏ);
    }

    @Nullable
    private tq<?> ˏ(tn tnVar, boolean z, long j) {
        if (!z) {
            return null;
        }
        tq<?> ॱ = ॱ((sa) tnVar);
        if (ॱ != null) {
            if (ˏ) {
                ॱ("Loaded resource from active resources", j, tnVar);
            }
            return ॱ;
        }
        ॱ = ˋ(tnVar);
        if (ॱ == null) {
            return null;
        }
        if (ˏ) {
            ॱ("Loaded resource from cache", j, tnVar);
        }
        return ॱ;
    }

    private static void ॱ(String str, long j, sa saVar) {
        Log.v("Engine", str + " in " + aaq.ˎ(j) + "ms, key: " + saVar);
    }

    @Nullable
    private tq<?> ॱ(sa saVar) {
        tq<?> ˎ = this.ʽ.ˎ(saVar);
        if (ˎ != null) {
            ˎ.ʼ();
        }
        return ˎ;
    }

    private tq<?> ˋ(sa saVar) {
        tq<?> ˊ = ˊ(saVar);
        if (ˊ != null) {
            ˊ.ʼ();
            this.ʽ.ˏ(saVar, ˊ);
        }
        return ˊ;
    }

    private tq<?> ˊ(sa saVar) {
        tx ॱ = this.ˋ.ॱ(saVar);
        if (ॱ == null) {
            return null;
        }
        if (ॱ instanceof tq) {
            return (tq) ॱ;
        }
        return new tq(ॱ, true, true, saVar, this);
    }

    public void ˊ(tx<?> txVar) {
        if (txVar instanceof tq) {
            ((tq) txVar).ʽ();
            return;
        }
        throw new IllegalArgumentException("Cannot release anything but an EngineResource");
    }

    public synchronized void ˊ(tk<?> tkVar, sa saVar, tq<?> tqVar) {
        if (tqVar != null) {
            if (tqVar.ˏ()) {
                this.ʽ.ˏ(saVar, tqVar);
            }
        }
        this.ˊ.ˋ(saVar, (tk) tkVar);
    }

    public synchronized void ˏ(tk<?> tkVar, sa saVar) {
        this.ˊ.ˋ(saVar, (tk) tkVar);
    }

    public void ॱ(@NonNull tx<?> txVar) {
        this.ʻ.ˋ(txVar);
    }

    public void ˏ(sa saVar, tq<?> tqVar) {
        this.ʽ.ˊ(saVar);
        if (tqVar.ˏ()) {
            this.ˋ.ˏ(saVar, tqVar);
        } else {
            this.ʻ.ˋ(tqVar);
        }
    }
}
